package model

import "time"

// ShoppingCart 购物车表
type ShoppingCart struct {
	BaseModel
	UserID  int32 `gorm:"type:int unsigned;index;comment:用户ID"` // 在购物车列表中我们需要查询当前用户的购物车记录
	GoodsID int32 `gorm:"type:int unsigned;index;comment:商品ID"`
	Nums    int32 `gorm:"type:int unsigned;comment:购买商品数量"`
	Checked bool  `gorm:"comment:是否选中该商品"`
}

type PayType uint8

const (
	PTUnspecified PayType = iota
	PTAlipay
	PTWechat
)

type OrderStatus uint8

const (
	OSUnspecified OrderStatus = iota
	OSTradeCreation
	OSWaitBuyerPay
	OSPaying
	OSTradeSuccess
	OSTradeClosed
	OSTradeFinished
)

// Order 订单信息表
type Order struct {
	BaseModel

	UserID  int32   `gorm:"type:int unsigned;index;comment:用户ID"`
	OrderSn int64   `gorm:"type:bigint;unique;comment:订单编号"` // 订单号，我们平台自己生成的订单号
	PayType PayType `gorm:"type:tinyint unsigned;comment:支付方式:1.alipay(支付宝), 2.wechat(微信)"`

	// status大家可以考虑使用iota来做
	Status      OrderStatus `gorm:"type:tinyint unsigned;comment:订单状态:1.TRADE_CREATION(交易创建), 2.WAIT_BUYER_PAY(待支付), 3.PAYING(支付中), 4.TRADE_SUCCESS(成功), 5.TRADE_CLOSED(超时关闭), 6.TRADE_FINISHED(交易结束)"`
	TradeNo     string      `gorm:"type:varchar(100);comment:第三方支付的交易号"` // 交易号就是支付宝的订单号 查账
	AmountCents int32       `gorm:"type:int;comment:订单金额(分)"`
	PayTime     *time.Time  `gorm:"comment:支付时间"`

	Address         string `gorm:"type:varchar(100);comment:收获地址"`
	ConsigneeName   string `gorm:"type:varchar(20);comment:收货人"`
	ConsigneeMobile string `gorm:"type:varchar(11);comment:收货人电话"`
	Post            string `gorm:"type:varchar(20);comment:加急"`
}

// OrderGoods 订单商品表
type OrderGoods struct {
	BaseModel

	OrderID int32 `gorm:"type:int unsigned;index;comment:订单ID"`
	GoodsID int32 `gorm:"type:int unsigned;index;comment:商品ID"`

	// 把商品的信息保存下来了,字段冗余,高并发系统中我们一般都不会遵循三范式 做镜像 记录
	GoodsName  string `gorm:"type:varchar(100);index;comment:商品名称"`
	GoodsImage string `gorm:"type:varchar(200);comment:商品图片"`
	GoodsPrice int32  `gorm:"type:int;comment:商品价格"`
	Nums       int32  `gorm:"type:int;comment:购买商品数量"`
}
